package org.infodavid.common.impl.services;

import org.infodavid.common.services.exceptions.IErrorHandler;
import org.infodavid.common.services.exceptions.ServiceException;

/**
 * The Class DefaultErrorHandler.
 */
public class DefaultErrorHandler implements IErrorHandler<ServiceException> {

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.services.exceptions.IErrorHandler#handle(java.lang.Throwable ,
	 * java.lang.String, java.lang.Object, int)
	 */
	public boolean handle(final Throwable error, final String message, final Object source,
	    final int retry) throws ServiceException {
		return handle(error, message, source);
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.services.exceptions.IErrorHandler#handle(java.lang.Throwable ,
	 * java.lang.String, java.lang.Object)
	 */
	public boolean handle(final Throwable error, final String message, final Object source)
	    throws ServiceException {
		if (error instanceof ServiceException) {
			throw (ServiceException)error;
		}

		throw new ServiceException(error.getMessage(), error);
	}
}
